package licode.unisop.types.dp;

import org.springframework.util.Assert;

public class Gender {
    public static final Gender MALE = new Gender(1);
    public static final Gender FEMALE = new Gender(2);

    private final int gender;

    public static Gender build(int gender) {
        Assert.isTrue(gender == 1 || gender == 2,
                "性别->1：男；2：女，当前：" + gender);
        if (gender == MALE.getGender()) {
            return MALE;
        } else {
            return FEMALE;
        }
    }

    public static Gender build(String gender) {
        Assert.isTrue("男".equals(gender) || "女".equals(gender),
                "性别->男或女，当前：" + gender);
        if ("男".equals(gender)) {
            return MALE;
        } else {
            return FEMALE;
        }
    }

    private Gender(int gender) {
        Assert.isTrue(gender == 1 || gender == 2,
                "性别->1：男；2：女，当前：" + gender);
        this.gender = gender;
    }

    public int getGender() {
        return gender;
    }

    @Override
    public String toString() {
        if (1 == gender) {
            return "男";
        }
        return "女";
    }
}
